import api from './request'
import type { ApiResponse } from './request'

// 分区管理API接口
export const zoneApi = {
  // 分页查询分区列表
  getZonePage: (params: any) => 
    api.get<ApiResponse<any>>('/api/region/zones', { params }),

  // 根据ID查询分区详情
  getZoneDetail: (id: number) => 
    api.get<ApiResponse<any>>(`/api/region/zones/${id}`),

  // 创建分区
  createZone: (data: any) => 
    api.post<ApiResponse<void>>('/api/region/zones', data),

  // 更新分区基本信息
  updateZoneInfo: (id: number, data: any) => 
    api.put<ApiResponse<void>>(`/api/region/zones/${id}/info`, data),

  // 更新分区
  updateZone: (id: number, data: any) => 
    api.put<ApiResponse<void>>(`/api/region/zones/${id}`, data),

  // 删除分区
  deleteZone: (id: number) => 
    api.delete<ApiResponse<void>>(`/api/region/zones/${id}`),

  // 根据小区ID查询分区列表
  getZonesByCommunity: (communityId: number) => 
    api.get<ApiResponse<any>>(`/api/region/zones/community/${communityId}`),

  // 根据物业公司ID查询分区列表
  getZonesByPropertyCompany: (propertyCompanyId: number) => 
    api.get<ApiResponse<any>>(`/api/region/zones/property-company/${propertyCompanyId}`),

  // 检查分区编码是否存在
  checkZoneCode: (zoneCode: string, excludeId?: number) => 
    api.get<ApiResponse<boolean>>('/api/region/zones/check-code', { 
      params: { zoneCode, excludeId } 
    })
}
